package com.superjson.showpro.shared.util;

import com.alibaba.fastjson.JSONObject;
import com.superjson.showpro.shared.enums.TitleEnum;

import java.util.LinkedHashSet;
import java.util.Set;

import static com.superjson.showpro.constants.ClassConstant.PACKEGE_PATH;
import static com.superjson.showpro.shared.util.JsonUtil.getJsonObject;
import static org.apache.commons.lang3.StringUtils.isBlank;

/**
 * Created By zby on 19:04 2019/5/30
 * 这是反射方法用的类
 */

public class MethodUtil {

    /**
     * Created By zby on 19:05 2019/5/30
     *
     * @param className 文件路径
     */
    public static Set getObject(String className) {
        if (isBlank(className)) {
            return null;
        }
        className = PACKEGE_PATH + className;
        try {
            Class<?> clazz = Class.forName(className);
            Object[] var = clazz.getEnumConstants();
            Set var1 = new LinkedHashSet(var.length);
            for (Object o : var) {
                if (o instanceof TitleEnum) {
                    var1.add(getJsonObject(o, "getValue"));
                }
            }
            return var1;
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return null;
    }


}
